<?php
class BpdRecord
{

public $fields;

function __construct()
{
	$this->fields = Array();
}

function Read($pfields)
{
	foreach ($pfields as $key=>$value) {
		$this->fields[$key] = $value;
	}
		
}

function TabTexte()
{
	echo '|';
	foreach ($this->fields as $field) {
		echo str_pad(substr($field,0,14),14).'|';
	}
	echo "\n";	
}
	
	
/*
	public $table;
	
	function __construct($ptable){
		$this->table = $ptable;
		foreach($this->table->fields as $field){
			$this->{$field->name} = $field->init;
		}
		foreach($this->table->rel_ext as $rel){
			$this->rel_ext[$rel->name] = Array();
		}
		foreach($this->table->rel_int as $rel){
			//$this->{$rel->prefixe.'id'} = $rel->Fields[$rel->Key];
			$this->rel_int[$rel->name] = Array();
		}
	}
	
	function Fields(){
		$retour = Array();
		foreach($this->table->fields as $field){
			$retour[$field->name] = $this->{$field->name};
		}
		return $retour;
	}
		
	function Read($id, $already = Array(), $follow=TRUE){
		global $Bpd_db;
		$sql = '';
		foreach($this->table->rel_ext as $rel){
			$sql = sprintf($rel->SelectRel(), $rel->prefixe.$this->table->key,$id);
			if ( $result=$Bpd_db->query($sql) ){
				while ( $row=$result->fetch_assoc() ){
					global ${'tbl_'.$rel->name};
					$BpdRecord = new BpdRecord(${'tbl_'.$rel->name});
					$BpdRecord->Import($row);
					$this->rel_ext[$rel->name][] = $BpdRecord;
				}
			}
		}
		$sql = sprintf($this->table->Select(), $id);
		if ( $result=$Bpd_db->query($sql) )
			while ( $row=$result->fetch_assoc() ){
				$this->Import($row);
			}
		foreach($this->table->rel_int as $rel){
			$sql = sprintf($rel->Select(), $this->{$rel->prefixe.'id'});
			if ( $result=$Bpd_db->query($sql) ){
				while ( $row=$result->fetch_assoc() ){
					global ${'tbl_'.$rel->name};
					$BpdRecord = new BpdRecord(${'tbl_'.$rel->name});
					$BpdRecord->Import($row);
					$this->rel_int[$rel->name][] = $BpdRecord;
				}
			}
		}
	}
	
	function ReadRecursive( $id, $already = Array() ){
		global $Bpd_db;
		$already[] = $this->table->name;
		$sql = sprintf($this->table->Select(), $id);
		if ( $result=$Bpd_db->query($sql) )
			while ( $row=$result->fetch_assoc() ){
				$this->Import($row);
			}
		foreach($this->table->rel_ext as $rel){
			if ( !in_array($rel->name, $already) ){
				$sql = sprintf($rel->SelectRel(), $rel->prefixe.$this->table->key,$id);
				if ( $result=$Bpd_db->query($sql) ){
					while ( $row=$result->fetch_assoc() ){
						$id = $row[$rel->key];
						global ${'tbl_'.$rel->name};
						$record = new BpdRecord(${'tbl_'.$rel->name});
						$record->ReadRecursive($id, $already);
						$this->rel_ext[$rel->name][] = $record;
					}
				}
			}
		}		
		foreach($this->table->rel_int as $rel){
			if ( !in_array($rel->name, $already) ){
				$sql = sprintf($rel->Select(), $this->{$rel->prefixe.'id'});
				if ( $result=$Bpd_db->query($sql) ){
					while ( $row=$result->fetch_assoc() ){
						$id = $row[$rel->key];
						global ${'tbl_'.$rel->name};
						$record = new BpdRecord(${'tbl_'.$rel->name});
						$record->ReadRecursive($id, $already);
						$this->rel_int[$rel->name][] = $record;
					}
				}
			}
		}
	}
	
	function Import($row){
		foreach($row as $key=>$value){
			$key = str_replace($this->table->prefixe, '', $key);
			if ( isset($this->$key) )
				$this->$key = $value;
		}
	}
	
	function Xml($tab=0, $already=array()){
		//$already[] = $this->table->name;
		$xml = '';
		$xml .= sprintxml($tab,sprintf('<%1$s label="%2$s">',$this->table->name, lng($this->table->name)));
		foreach($this->table->fields as $field){
			$name = $this->table->prefixe.$field->name;
			$xml .= sprintxml($tab+1,sprintf('<%1$s label="%3$s">%2$s</%1$s>', $name, $this->{$field->name}, lng($name)));
		}
		$xml_int = '';
		foreach ($this->table->rel_int as $rel){
			foreach ($this->rel_int[$rel->name] as $record)
				$xml_int .= $record->Xml($tab+2);
		}
		if ( $xml_int ) {
			$xml .= sprintxml($tab+1,"<rel_int>");
			$xml .= $xml_int;
			$xml .= sprintxml($tab+1,"</rel_int>");
		}
		foreach ($this->table->rel_ext as $rel){
			$xml_ext = '';
			foreach ($this->rel_ext[$rel->name] as $record)
				$xml_ext .= $record->Xml($tab+2);
			if ( $xml_ext ) {
				$xml .= sprintxml($tab+1,"<rel_ext>");
				$xml .= $xml_ext;
				$xml .= sprintxml($tab+1,"</rel_ext>");
			}
		}
		$xml .= sprintxml($tab,"</{$this->table->name}>");
		return $xml;
	}
*/
}// class BpdRecord
?>
